﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace zifuchuan
{
    class myFunction
    {
        /// <summary>
        /// 自己写的函数
        /// </summary>
        public void Run()
        {
            String strTest = "i am in the classroom.";

            String strResult = JiaMi(strTest);

            Console.WriteLine(strTest);
            Console.WriteLine(strResult);
        }


        /// <summary>
        /// 加密函数，把一串字符串按照自己的规定转化为
        /// 另外一串字符串
        /// </summary>
        /// <param name="source">输入字符串</param>
        /// <returns>输出字符串</returns>
        public String JiaMi(String source)
        {
            String strRtn = String.Empty;


            // 1 遍历字符串里每一个字符
            // 2 把字符按照自己规定变为数字
            // 3 组合这些数字


            // 字符串长度.
            int nNum = source.Length;
            for (int i = 0; i < nNum; i++)
            {
                // 获得每一个字符
                char each = source[i];

                // 把字符变为数字.
                int nEach = Change(each);

                // 把数字组合为一个新的字符串.
                // 每两个数字之间有一个空格.
                strRtn = strRtn + nEach.ToString() + " ";

            }

            return strRtn;
        }

        /// <summary>
        /// 把字符变为数字
        /// </summary>
        /// <param name="each">输入的字符</param>
        /// <returns>设定的数字</returns>
        public int Change(char each)
        {
            int nRtn = 0;

            switch (each)
            {
                case 'a': nRtn = 1; break;
                case 'b': nRtn = 2; break;
                case 'c': nRtn = 3; break;
                case 'd': nRtn = 4; break;
                case 'e': nRtn = 5; break;
                case 'f': nRtn = 6; break;
                case 'g': nRtn = 7; break;
                case 'h': nRtn = 8; break;
                case 'i': nRtn = 9; break;
                case 'j': nRtn = 10; break;
                case 'k': nRtn = 11; break;
                case 'l': nRtn = 12; break;
                case 'm': nRtn = 13; break;
                case 'n': nRtn = 14; break;
                case 'o': nRtn = 15; break;
                case 'p': nRtn = 16; break;
                case 'q': nRtn = 17; break;
                case 'r': nRtn = 18; break;
                case 's': nRtn = 19; break;
                case 't': nRtn = 20; break;
                case 'u': nRtn = 21; break;
                case 'v': nRtn = 22; break;
                case 'w': nRtn = 23; break;
                case 'x': nRtn = 24; break;
                case 'y': nRtn = 25; break;
                case 'z': nRtn = 26; break;
                case ' ': nRtn = 27; break;
                case '.': nRtn = 28; break;

            }

            return nRtn;
        }
    }
}
